import {
  Entity,
  Column,
  OneToMany,
  Generated,
  PrimaryGeneratedColumn,
  PrimaryColumn,
} from 'typeorm';
import { BaseEntity } from './base.entity';
import { DictItem } from './dict-item.entity';
import { ApiProperty } from '@nestjs/swagger';
import * as crypto from 'crypto';

@Entity()
export class Dict extends BaseEntity {
  constructor() {
    super();
    this.id = crypto.randomBytes(8).toString('hex');
  }

  @PrimaryColumn({ length: 225 })
  @ApiProperty({
    required: false,
    description: '字典id',
  })
  id: string;

  @ApiProperty({
    required: false,
    description: '描述',
  })
  @Column({ nullable: true }) // 设置为可为空
  description: string;

  @ApiProperty({
    required: false,
    description: '字典标识',
  })
  @Column({ nullable: true }) // 设置为可为空
  dictCode: string;

  @ApiProperty({
    required: false,
    description: '字典名称',
  })
  @Column({ nullable: true }) // 设置为可为空
  dictName: string;

  @OneToMany(() => DictItem, (dictItem) => dictItem.dict, {
    cascade: true,
    onDelete: 'CASCADE',
  })
  dictItems: DictItem[];
}
